<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <span id="show"></span><br>
    <span id="show1"></span>
    <script>
        // 4.时间差 和 页面停留时间

        
        
        // 时间差
        function chatimes(date1,date2){
            var time1 = date1.getTime()
            var time2 = date2.getTime()
            var chatime = time2 - time1
            chatime /= 1000
            var sec = parseInt(chatime % 60)
            var min = parseInt((chatime  / 60) % 60)
            var hours = parseInt((chatime / 3600)% 24)
            var days = parseInt(chatime / 3600 / 24)
            console.log(days)
            return  ' ' + days + ' 天 ' + hours + ' 小时 ' + min + ' 分 ' + sec + ' 秒 '
        }

        // 倒计时
        setInterval(function(){
            var nowDate = new Date()
            var duanwujie = new Date('2020/6/25')
            show.innerHTML = '距离端午节还有' + chatimes(nowDate,duanwujie)
        },1000)
        



        //页面停留时间
        var pertime = new Date()
        var  curtime = new Date()


        setInterval(function(){
            var  curtime = new Date()
            show1.innerHTML = chatimes(pertime,curtime)
        },1000)
    </script>
</body>
</html>